#include "./res/m.h"

char buf[2];
char *rcv_buf = NULL;
static char cs_buf[1024] = {0};

void LED_blink(char *rcv_buf_cb)
{
    int time_d;
    
    // 打开文件
	int fd = open("/dev/led_drv",O_RDWR);
	if(fd == -1)
	{
		perror("open");
		return;
	}
    
    strcpy(cs_buf, rcv_buf_cb);
    strtok(cs_buf, "\n");
    rcv_buf = strtok(NULL, "\n");
    
    if(strcmp(rcv_buf, "temperature:3")<0)
    {
        time_d = 1000000;
    }
    
    else if(strcmp(rcv_buf, "temperature:3")>=0)
    {
        time_d = 500000;
    }
    
    
    //死循环挂起灯光闪烁
    while(1)
    {
        buf[0] = 1;//全部开灯
        buf[1] = 7; //灯的编号
        write(fd,buf,sizeof(buf));
        buf[1] = 8; //灯的编号
        write(fd,buf,sizeof(buf));
        buf[1] = 9; //灯的编号
        write(fd,buf,sizeof(buf));
        buf[1] = 10; //灯的编号
        write(fd,buf,sizeof(buf));

        // 标志更新
        LED_state_flag = 1; 
        // 阻塞延时?秒
        usleep(time_d);
        
        buf[0] = 0;//全部关灯
        buf[1] = 7; //灯的编号
        write(fd,buf,sizeof(buf));
        buf[1] = 8; //灯的编号
        write(fd,buf,sizeof(buf));
        buf[1] = 9; //灯的编号
        write(fd,buf,sizeof(buf));
        buf[1] = 10; //灯的编号
        write(fd,buf,sizeof(buf));

        // 标志更新
        LED_state_flag = 0; 
        // 阻塞延时?秒
        usleep(time_d);
    }
    

    return;
}